var memberPayService = {id: "MemberPayServiceTable", seItem: null, table: null, layerIndex: -1};
memberPayService.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle',},
        {title: '序号', field: 'num', align: 'center', valign: 'middle', sortable: true},
        {title: '科室', field: 'department', align: 'center', valign: 'middle', sortable: true},
        {title: '一级项目', field: 'firstLevelProject', align: 'center', valign: 'middle', sortable: true},
        {title: '产品项目', field: 'payServiceName', align: 'center', valign: 'middle', sortable: true},
        {title: '价格1', field: 'payServicePriceOne', align: 'center', valign: 'middle', sortable: true},
        {title: '价格2', field: 'payServicePriceTwo', align: 'center', valign: 'middle', sortable: true},
        {title: '单位', field: 'unit', align: 'center', valign: 'middle', sortable: true},
        {title: '开单状态', field: 'isDeal', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "结账算成交"
                } else {
                    return "结账不算成交"
                }
            }},
        {title: '上架状态', field: 'isUpper', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "已上架"
                } else {
                    return "未上架"
                }
            }
        },
        {title: '前台可开单', field: 'isTeethProject', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "是"
                } else {
                    return "不是"
                }
            }
        },
        {title: '可免费项目', field: 'freeService', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "是"
                } else {
                    return "不是"
                }
            }
        },
        {title: '备注', field: 'remarks', align: 'center', valign: 'middle', sortable: true},]
};

memberPayService.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        memberPayService.seItem = selected[0];
        return true;
    }
};

//会员免费项目
memberPayService.freeService = function () {
    if (this.check()) {
        var id = memberPayService.seItem.id;
        var index = layer.open({
            type: 2,
            title: '会员免费项目设置',
            area: ['40%', '60%'],
            fix: true,
            maxmin: true,
            content: Feng.ctxPath + '/memberPayService/freeService/' + id
        });
        this.layerIndex = index;
    }
}

memberPayService.formParams = function () {
    var queryData = {};
    queryData['treatmentUnit'] = $("#treatmentUnit").val();
    queryData['firstLevelProjectDivsd'] = $("#firstLevelProjectDivsd").val();
    queryData['isUpperStatus'] = $("#isUpperStatus").val();
    queryData['payServiceName'] = $("#payServiceName").val();
    queryData['isDeal'] = $("#isDeal").val();
    queryData['isTeethProject'] = $("#isTeethProject").val();
    return queryData
};
memberPayService.resetSearch = function () {
    $("#payServiceName").val("");
    memberPayService.search()
};
memberPayService.search = function () {
    memberPayService.table.refresh({query: memberPayService.formParams()})
};
memberPayService.getFirstLevelProjectByTreatmentUnit = function () {
    $.ajax({
        url: Feng.ctxPath + "/payService/getFirstLevelProjectByTreatmentUnit",
        type: "post",
        data: {treatmentUnit: $("#treatmentUnit").val()},
        success: function (data) {
            var txt = '<option value="">请选择</option>';
            for (var i = 0; i < data.length; i++) {
                txt += ' <option value="' + data[i].firstLevelProject + '"> ' + data[i].firstLevelProject + '</option>'
            }
            document.getElementById('firstLevelProjectDivsd').innerHTML = txt
        }
    });
    memberPayService.search()
};
$(function () {
    var defaultColunms = memberPayService.initColumn();
    var table = new BSTable(memberPayService.id, "/memberPayService/memberPayServicelist", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(memberPayService.formParams());
    memberPayService.table = table.init();
    memberPayService.table = table
});